﻿<h2><?= $this->translate("Category") ?>: <?= $this->category->translate("name") ?></h2>
<?php if ( isset($this->products) and count($this->products) > 0 ) { ?>
    <?php
        require_once('Zend/Currency.php');
        $currency = new Zend_Currency('cs_CZ');
    ?>
    <div id="catalog"> 
    	<table cellpadding="0" cellspacing="0">
    	<?php $x = 0 ?>	   
        <?php foreach( $this->products as $product ) { ?>
            <?php if ($x%3 == 0) { ?>
                <tr>
            <?php } ?>
                <td>
            		<div class="header">
            			<div class="sale">
             				<a href="<?= $this->url(array('controller'=>'product-catalogue','action'=>'detail','id'=>$product->id)) ?>" title="<?= $product->translate("name")?>"><?= $product->translate("name") ?></a>
            			</div><!-- class sale -->
            			<div class="cat_image">
            			    <?php if (!empty($product->image)) { ?>
            				    <a href="<?= $this->url(array('controller'=>'product-catalogue','action'=>'detail','id'=>$product->id)) ?>" title="<?= $product->translate("name")?>"><img src="<?= $this->publicUrl . "Products/Thumbs/" . $product->image ?>" alt="<?= $product->translate("name") ?>"/></a>
            				<?php } ?>
            			</div>
            		</div><!-- id header-->
            		
            		<div class="grey left"><?= $this->translate('Price') ?>: </div>
            		<div class="red right"><?= $currency->toCurrency($product->price) ?></div>
            		
            		<p class="description">
            			<?php
            			$wordWrapDescription = wordwrap($product->translate('description'), '50',"...\n");
                        $endPosition = (strpos($wordWrapDescription, "...\n")) ? strpos($wordWrapDescription, "...\n")+3 : strlen($wordWrapDescription);
            			 echo substr($wordWrapDescription,0,$endPosition) ?>
            		</p>
            		<div class="downstrip">
            			<div class="left">
            				<div id="submitbutton">
            					<a href="<?= $this->url(array('controller'=>'product-catalogue','action'=>'detail','id'=>$product->id)); ?>" title="<?= $this->translate('Product Detail') ?>"><?= $this->translate('Detail') ?></a>
            				</div>
            			</div>
            			<div class="right">
            			    <div id="submitbutton2">	    	
            			    	<?php if (!empty($this->user)) { ?>		    
            			    		<a href="<?= $this->url(array('controller' => 'user-basket', 'action' => 'add-basket-item', 'id' => $product->id, 'amount' => '1')) ?>" title="<?= $this->translate('Buy') ?>"><?= $this->translate('Buy') ?></a>
        						<?php } else { ?>
            			    		<a href="#" title="<?= $this->translate('Log in to buy') ?>!"><?= $this->translate('Buy') ?></a>
            					<?php } ?>
            				</div>
            			</div>
            		</div><!-- id downstrip -->
            	</td>
        	<?php $x++ ?>
        	<?php if ($x%3 == 0) { ?>
                </tr>
            <?php } ?>        
        <?php } ?>
        <?php 
        if ($x%3 != 0) {
            while ($x%3 != 0) {
                echo "<td></td>";
                $x++;
            }
            echo "</tr>";
        }
        ?>
        </table>
        <center><?= $this->paginationControl($this->products, 'Sliding', 'paginatorControl.phtml') ?></center>
	</div>
	
	
<?php } else { ?>
	<p><?= $this->translate("No products found in category") ?></p>
<?php } ?>